import { APICartList  } from './fetch.js';
import { getCookie } from './tools.js';


// $('#head').load('../../layout/head.html');
// $('#foot').load('../../layout/foot.html');

layui.use(['layer'], function () {
  var layer = layui.layer;


  var username = getCookie('login_user');

  APICartList({
    username
  }).then(({ data }) => {
    var html = '';
    
    $.each(data, (index, { gname, img, price, count, id }) => {
      html += `
      <div id="order_biao">
            <div id="order_img"><img
                    src="${img}" alt=""></div>
            <div id="order_a">
                <span>${gname}</span>
                <p>规格:定制诚意金（具体价格以设计方案为准，详情<br>咨询客服）</p>

            </div>
            <div id="order_b">￥${price}</div>
            <div id="order_c">${count}</div>
            <div id="order_d">￥<span id="qqq">${(price * count).toFixed(2)}</span></div>
        </div>
    `
    })

    $('#order_boss').html(html);
    
    getTotal()
   
  })

 
  function getTotal() {
    
    var total = 0;
    var rr = document.querySelectorAll('#qqq')
    $.each(rr, function (_, item) {
      
      total +=  $(this).parents('#order_biao').find('#order_d #qqq').text() *1
    });
  

  
  
  
    $('#order_dowm_c #priceTotal').text(total.toFixed(2));
    $('#order_dowm_b #zong').text(total.toFixed(2));
  }
  })



